package view.component.tip
{
import mapengine.interfaces.IFactoryBuilding;

import utils.TimeUtil;

/**
 * FactoryBuildingProduceTip
 * @author jliang
 *
 */
public class FactoryBuildingProduceTip extends MapBuildingTip
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function FactoryBuildingProduceTip()
	{
		super();
	}
	//==========================================================================
	//  Overridden methods: MapBuildingTip
	//==========================================================================
	override protected function get skinReference():String
	{
		return "swf.ui.FactoryBuildingProduceTipSkin";
	}
	
	override public function dispose():void
	{
		TimeUtil.removeRenderFunction(update);
		
		super.dispose();
	}
	
	override protected function init():void
	{
		skin.nameLabel.text = data.buildingItemValue.template.name;
		
		TimeUtil.addRenderFunction(update);
		
		update();
	}
	
	protected function update():void
	{
		if (!IFactoryBuilding(data).isProducing)
		{
			if (this.parent)
			{
				this.parent.removeChild(this);
			}
			this.dispose();
			return;
		}
		
		skin.timeLabel.text = TimeUtil.parseSecsToString(IFactoryBuilding(data).factoryBuildingItemValue.produceTimeRest);
	}
}
}



